home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gsview10.zip / gsview.c < prev    next >
C/C++ Source or Header  |  1993-07-29  |  37KB  |  1,313 lines

  1. /*
  2.  * gsview.c -- Main module of GSVIEW.EXE, a graphical interface for 
  3.  *             MS-Windows Ghostscript
  4.  * Copyright (C) 1993  Russell Lang
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *   Author: Russell Lang
  21.  * Internet: rjl@monu1.cc.monash.edu.au
  22.  */
  23.  
  24. #define STRICT
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include <commdlg.h>
  28. #include <shellapi.h>
  29. #include <mmsystem.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <dir.h>
  35. #include <io.h>
  36. #define NeedFunctionPrototypes 1
  37. #include "ps.h"
  38. #include "gsview.h"
  39.  
  40. char szAppName[MAXSTR];            /* application name - for title bar */
  41. const char szClassName[] = "gsview_class";
  42. const char szScratch[] = "gsview";    /* temporary filename prefix */
  43.  
  44. HWND hwndimg;            /* gsview main window */
  45. HWND hDlgModeless;        /* any modeless dialog box */
  46. HWND hwndtext;            /* gswin text window */
  47. HWND hwndimgchild;        /* gswin image child window */
  48. HINSTANCE phInstance;        /* instance of gsview */
  49. HINSTANCE gswin_hinst;        /* instance of gswin */
  50. int bitmap_scrollx=0;        /* offset from bitmap to origin of child window */
  51. int bitmap_scrolly=0;
  52. int bitmap_width;        /* size of gswin bitmap in pixels */
  53. int bitmap_height;
  54.  
  55. /* these can be saved in the INI file */
  56. char szGSwin[128];        /* command to invoke gswin */
  57. POINT img_origin;        /* gsview window origin */
  58. POINT img_size;            /* gsview window size */
  59. BOOL quick;            /* use quick opening (don't reload gswin) */
  60. BOOL settings;            /* save settings on exit */
  61. BOOL button_show;        /* show buttons bar */
  62. int media;            /* IDM_LETTER etc. */
  63. char medianame[32];        /* name of media */
  64. int user_width, user_height;    /* User Defined media size */
  65. BOOL epsf_clip;            /* make bitmap size of epsf bounding box */
  66. BOOL epsf_warn;            /* write warning messages if operators incompatible with EPS are used */
  67. BOOL redisplay;            /* redisplay on resize */
  68. BOOL safer;            /* use -dSAFER option */
  69. int orientation;        /* IDM_PORTRAIT, IDM_LANDSCAPE etc. */
  70. BOOL swap_landscape;        /* swap IDM_LANDSCAPE & IDM_SEASCAPE */
  71. float xdpi, ydpi;        /* resolution of gswin bitmap */
  72. UINT timeout;            /* default timeout period in 1 sec units */
  73. BOOL save_dir;            /* remember current directory for next time */
  74. char device_name[32];        /* printer name */
  75. char device_resolution[32];    /* printer resolution */
  76.  
  77. struct sound_s sound[NUMSOUND] = {
  78.     {"SoundOutputPage", IDS_SNDPAGE, ""},
  79.     {"SoundNoPage", IDS_SNDNOPAGE, BEEP},
  80.     {"SoundNoNumbering", IDS_SNDNONUMBER, ""},
  81.     {"SoundNotOpen", IDS_SNDNOTOPEN, ""},
  82.     {"SoundError", IDS_SNDERROR, BEEP},
  83.     {"SoundTimeout", IDS_SNDTIMEOUT, ""},
  84.     {"SoundStart", IDS_SNDSTART, ""},
  85.     {"SoundExit", IDS_SNDEXIT, ""},
  86. };
  87.  
  88.  
  89. /* initialised in init.c */
  90. BOOL is_win31 = FALSE;        /* To allow selective use of win 3.1 features */
  91. char szHelpName[MAXSTR];    /* buffer for building help filename */
  92. char szHelpTopic[48];        /* topic for OFN_SHOWHELP */
  93. UINT help_message;        /* message sent by OFN_SHOWHELP */
  94. HMENU hmenu;            /* main menu */
  95. HACCEL haccel;            /* menu accelerators */
  96. HCURSOR hcWait;
  97. POINT img_offset;        /* offset to gswin child window */
  98. POINT info_file;        /* position of file information */
  99. POINT info_page;        /* position of page information */
  100. RECT  info_rect;        /* position and size of brief info area */
  101. RECT  info_coord;        /* position and size of coordinate information */
  102. RECT  button_rect;        /* position and size of button area */
  103.  
  104. BOOL prev_in_child;        /* true if cursor previously in gswin child window */
  105. BOOL waiting = FALSE;        /* true when 'wait' to be displayed in info area */
  106. BOOL page_ready = FALSE;    /* true when gswin has sent an OUTPUT_PAGE and is waiting for NEXT_PAGE */
  107. BOOL saved = FALSE;        /* true if interpreter state currently saved in /gssave */
  108. BOOL epsf_clipped;        /* clipping this page? */
  109. int page_skip = 5;        /* number of pages to skip in IDM_NEXTSKIP or IDM_PREVSKIP */
  110. int page_extra;            /* extra pages to skip */
  111. BOOL debug = FALSE;        /* /D command line option used */
  112. HINSTANCE hlib_mmsystem;    /* DLL containing sndPlaySound function */
  113. FPSPS lpfnSndPlaySound;        /* pointer to sndPlaySound function if loaded */
  114.  
  115. /* timer used for open, close, display & print timeouts */
  116. BOOL bTimeout;            /* true if timeout occured */
  117. BOOL bTimerSet;            /* true if TIMER running */
  118. #define ID_MYTIMER 1
  119. UINT timeout_count;
  120.  
  121. /* document manipulation */
  122. struct document *doc;    /* DSC structure.  NULL if not DSC */
  123. int pagenum;        /* current page number */
  124. char dfname[MAXSTR];    /* name of selected document file */
  125. char efname[MAXSTR];    /* name of temporary file containing PS extracted 
  126.                            from DOS EPS file */
  127. FILE *dfile;        /* selected file */
  128. FILE *cfile;        /* command file (pipe) */
  129. BOOL is_ctrld;        /* TRUE if DSC except for ctrl+D at start of file */
  130. int preview;        /* preview type IDS_EPSF, IDS_EPSI, etc. */
  131. struct page_list_s page_list;    /*  page selection for print/extract */
  132.  
  133. /* local functions */
  134. BOOL draw_button(DRAWITEMSTRUCT FAR *lpdis);
  135. BOOL in_child_client_area(void);
  136. BOOL in_client_area(void);
  137. BOOL in_info_area(void);
  138. void info_paint(HWND);
  139. void gsview_close(void);
  140. int gsview_command(WORD);
  141. BOOL not_open(void);
  142. BOOL not_dsc(void);
  143.  
  144. int PASCAL 
  145. WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
  146. {
  147.     MSG msg;
  148.  
  149.     /* copy the hInstance into a variable so it can be used */
  150.     phInstance = hInstance;
  151.  
  152.     LoadString(hInstance, IDS_TITLE, szAppName, sizeof(szAppName));
  153.     if (hPrevInstance) {
  154.         /* don't run more than one copy */
  155.         /* because we can't run more than one Ghostscript */
  156.         gsview_init0(lpszCmdLine);
  157.         return FALSE;
  158.     }
  159.  
  160.     gsview_init1(lpszCmdLine);
  161.     ShowWindow(hwndimg, cmdShow);
  162.     
  163.     while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
  164.         if ((hDlgModeless == 0) || !IsDialogMessage(hDlgModeless, &msg)) {
  165.             if (!TranslateAccelerator(hwndimg, haccel, &msg)) {
  166.             TranslateMessage(&msg);
  167.             DispatchMessage(&msg);
  168.             }
  169.         }
  170.     }
  171.  
  172.     play_sound(SOUND_EXIT);
  173.     gsview_close();
  174.      WinHelp(hwndimg,szHelpName,HELP_QUIT,(DWORD)NULL);
  175.     if (is_win31 && (hlib_mmsystem != (HINSTANCE)NULL))
  176.         FreeLibrary(hlib_mmsystem);
  177.     return 0;
  178. }
  179.  
  180.  
  181. /* parent overlapped window */
  182. LRESULT CALLBACK _export
  183. WndImgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185. RECT rect;
  186.  
  187.     if (message == WM_GSVIEW) {
  188.     switch(wParam) {
  189.         case HWND_TEXT:
  190.         /* lParam = handle to Ghostscript Borland EasyWin window */
  191.         hwndtext = (HWND)lParam;
  192.         break;
  193.         case HWND_IMGCHILD:
  194.         /* lParam = handle to Ghostscript image child window */
  195.         hwndimgchild = (HWND)lParam;
  196.         if (hwndimgchild && IsWindow(hwndimgchild)) {
  197.             SetClassCursor(hwndimgchild, LoadCursor((HINSTANCE)NULL, IDC_CROSS));
  198.             GetClientRect(hwnd, &rect);
  199.             SetWindowPos(hwndimgchild, (HWND)NULL, rect.left+img_offset.x, rect.top+img_offset.y,
  200.             rect.right-img_offset.x, rect.bottom-img_offset.y, 
  201.             SWP_NOZORDER | SWP_NOACTIVATE);
  202.         }
  203.         break;
  204.         case GSWIN_CLOSE:
  205.         /* something is closing gswin */
  206.         gswin_hinst = (HINSTANCE)NULL;
  207.         hwndimgchild = (HWND)NULL;
  208.         hwndtext = (HWND)NULL;
  209.         bitmap_scrollx = bitmap_scrolly = 0;
  210.         page_ready = FALSE;
  211.         page_extra = 0;
  212.         saved = FALSE;
  213.         pipeclose();
  214.         clear_timer();
  215.         info_wait(FALSE);
  216.         break;
  217.         case OUTPUT_PAGE:
  218.         /* showpage has just been called */
  219.         clear_timer();
  220.         play_sound(SOUND_PAGE);
  221.         if (IsIconic(hwndimg))    /* useless as an Icon so fix it */
  222.             ShowWindow(hwndimg, SW_SHOWNORMAL);